using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
using Microsoft.Win32;

using SypEngine;
using SypConst.Garbage;
using SypConst.Path;

namespace SypEngine
{
    public class SypSiteVisitor : SypVisitor
    {
        #region private methods
       
        private void CopyFile(string srcDirectory, string destDirectory, string ftpDirectory, SypSiteHandler siteObj, int siteId)
        {
            string[] files = Directory.GetFiles(srcDirectory);
            foreach (string file in files)
            {
                string filename = SypGarbage.GetFileName(file);
                siteObj.AddAction(siteId, new string[] { file, destDirectory + filename }, SyncAction.COPY_FILE, SyncMode.LOCAL);
                if (ftpDirectory != null)
                {
                    string ToUpFolder = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.TOUP_FOLDER, null, siteId);
                    siteObj.AddAction(siteId, new string[] { file, ToUpFolder + filename }, SyncAction.COPY_FILE, SyncMode.LOCAL);
                }
                
                if (ftpDirectory != null)
                    siteObj.AddAction(siteId, ftpDirectory + filename, SyncAction.ADD_FILE, SyncMode.ONLINE);
            }
            SypGarbage.free(files);
        }

        #endregion


        public SypSiteVisitor(SetText WriteMethod, VisitorCallBack[] Callbacks)
            : base(WriteMethod, Callbacks)
        {
        }


        #region Action visitors

        public void VisitShowoptionsMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (parameters.Length > 1)
            {
                int SiteId = -1;
                if (int.TryParse(parameters[1], out SiteId))
                {
                    if (Callbacks.Length > 2)
                        Callbacks[2](SiteId);
                }
                else
                    OutputMethod("Showoptions-site : cannot convert " + SiteId + "in int type.", Output.ERROR);
            }
            else
                OutputMethod("Showoptions-site : missing parameters", Output.ERROR);
        }

        public override void VisitAddMethod(SypSiteHandler SiteObj,  string[] parameters)
        {     
            if (parameters.Length > 2)
            {
                SypSite newSite = null;
                if (parameters.Length == 3)
                    newSite = new SypSite(cleanArg(parameters[2]), cleanArg(parameters[1]), ref SiteObj.SiteIdUsed);
                else if (parameters.Length > 3)
                    newSite = new SypSite(cleanArg(parameters[2]), cleanArg(parameters[1]), ref SiteObj.SiteIdUsed, cleanArg(parameters[3]));
                else
                {
                    OutputMethod("Add-site : parameter missing", Output.ERROR);  
                    return;
                }
                if (SypPathHandler.CheckForInitializing(newSite.design))
                {
                    SiteObj.AddAction(newSite.SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.SITE_FOLDER, null, newSite.SiteId), SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.ROOT_FOLDER, null, newSite.SiteId), SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.TOUP_FOLDER, null, newSite.SiteId), SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.ZIP_FOLDER, null, newSite.SiteId), SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.ROOT_FOLDER, null, newSite.SiteId), SyncAction.ADD_FOLDER, SyncMode.ONLINE);

                    //create stylesheet folder local and online
                    string SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.STYLESHEET_FOLDER, newSite.design, newSite.SiteId);
                    string LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.STYLESHEET_FOLDER, null, newSite.SiteId);
                    string OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.STYLESHEET_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);

                    //create static html page
                    //SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.ADMIN_STATIC_FOLDER, newSite.design, newSite.SiteId);
                    //LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.ROOT_FOLDER, null, newSite.SiteId);
                    //OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.ROOT_FOLDER, null, newSite.SiteId);
                    //CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);
                    
                    //create local xslt folder
                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.XSLT_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.XSLT_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.XSLT_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    CopyFile(SrcDirectory, LocalDirectory, null, SiteObj, newSite.SiteId);

                    //create pictures folder local and online
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.PICTURE_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.PICTURE_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);

                    //create Thumbnail folder local and online
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.THUMBNAIL_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.THUMBNAIL_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);

                    //create Javascript folder local and online
                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.JAVASCRIPT_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.JAVASCRIPT_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.JAVASCRIPT_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    //create Images folder local and online
                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.IMAGE_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.IMAGE_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.IMAGE_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    //create Pages folder local and online
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.CATEGORIES_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.CATEGORIES_FOLDER, null, newSite.SiteId);
                    SiteObj.AddAction(newSite.SiteId, LocalDirectory, SyncAction.ADD_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(newSite.SiteId, OnlineDirectory, SyncAction.ADD_FOLDER, SyncMode.ONLINE);


                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.ADMIN_STYLESHEET_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.STYLESHEET_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.STYLESHEET_FOLDER, null, newSite.SiteId);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.ADMIN_JAVASCRIPT_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.JAVASCRIPT_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.JAVASCRIPT_FOLDER, null, newSite.SiteId);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.ADMIN_IMAGE_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.IMAGE_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.IMAGE_FOLDER, null, newSite.SiteId);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    SrcDirectory = SypPathHandler.GetPath(SypPathMode.DESIGN, SypPathRef.ADMIN_XSLT_FOLDER, newSite.design, newSite.SiteId);
                    LocalDirectory = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.XSLT_FOLDER, null, newSite.SiteId);
                    OnlineDirectory = SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.XSLT_FOLDER, null, newSite.SiteId);
                    CopyFile(SrcDirectory, LocalDirectory, OnlineDirectory, SiteObj, newSite.SiteId);


                    SiteObj.AddSite(newSite);
                    OutputMethod("Add-site [" + newSite.SiteId + "] site added successfully", Output.OUT);
                }
                else
                {
                    OutputMethod("Add-site [" + newSite.SiteId + "]: initializing process failed", Output.ERROR);
                    SypGarbage.free(newSite);
                }
            }
            else
                OutputMethod("Add-site : parameter missing", Output.ERROR);  
        }

        public void VisitSetconnectionMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (parameters.Length > 3)
            {
                int SiteId = -1;
                try
                {
                    SiteId = int.Parse(cleanArg(parameters[1]));
                }
                catch (Exception)
                {
                    OutputMethod("Setconnection-site : connection mode is not a number", Output.ERROR);
                    return;
                }
                SypSite mySite = SiteObj.GetSiteConfig(SiteId);
                if (mySite != null)
                {
                    int modeConnexion = -1;

                    //Connexion MODE
                    if (int.TryParse(parameters[2], out modeConnexion))
                    {
                        switch ((ConnectionMode)modeConnexion)
                        {
                            case ConnectionMode.FTP_MODE:
                                {
                                    //param 3 : FTP Hostname
                                    mySite.SypTfConf.Hostname = cleanArg(parameters[3]);

                                    //param 4 : FTP port
                                    int port = -1;
                                    if (int.TryParse(parameters[4], out port))
                                        mySite.SypTfConf.Port = port;
                                    else
                                        OutputMethod("Setconnection-site : port parameter is not a number", Output.ERROR);

                                    //param 5 : FTP password
                                    mySite.SypTfConf.Password = cleanArg(parameters[5]);

                                    //param 6 : FTP login
                                    mySite.SypTfConf.Login = cleanArg(parameters[6]);

                                    //param 7 : FTP Remote Path
                                    mySite.SypTfConf.RemoteDir = cleanArg(parameters[7]);


                                    mySite.SiteConnectionMode = ConnectionMode.FTP_MODE;

                                    break;
                                }

                            case ConnectionMode.SCP_MODE:
                                {
                                    //param 3 : FTP Hostname
                                    mySite.SypTfConf.Hostname = cleanArg(parameters[3]);

                                    //param 4 : FTP password
                                    mySite.SypTfConf.Password = cleanArg(parameters[4]);

                                    //param 5 : FTP login
                                    mySite.SypTfConf.Login = cleanArg(parameters[5]);

                                    //param 6 : FTP Remote Path
                                    mySite.SypTfConf.RemoteDir = cleanArg(parameters[6]);

                                    //param 7 : FTP Remote Path
                                    int port = -1;
                                    if (int.TryParse(parameters[7], out port))
                                        mySite.SypTfConf.Port = port;
                                    else
                                        OutputMethod("Setconnection-site : port parameter is not a number", Output.ERROR);

                                    mySite.SiteConnectionMode = ConnectionMode.SCP_MODE;
                                    break;
                                }

                            case ConnectionMode.DIRECT_MODE:
                                {
                                    //param 3 : FTP Remote Path
                                    mySite.SypTfConf.RemoteDir = cleanArg(parameters[3]);

                                    mySite.SiteConnectionMode = ConnectionMode.DIRECT_MODE;
                                    break;
                                }

                            default:
                                {
                                    break;
                                }

                        }
                    }
                    else
                        OutputMethod("Setconnection-site : modeConnexion parameter is not a number", Output.ERROR);
                }
                else
                    OutputMethod("[" + SiteId + "]Setconnection-site : unknown siteId " + SiteId, Output.ERROR);
            }

            else
                OutputMethod("Setconnection-site : parameters missing", Output.ERROR);
        }
    
        public override void VisitEditMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (parameters.Length > 2)
            {
                int SiteId = -1;
                try
                {
                    SiteId = int.Parse(cleanArg(parameters[1]));
                }
                catch (Exception)
                {
                    OutputMethod("Edit-site : siteId is not a number", Output.ERROR);
                    return;
                }
                SypSite mySite = SiteObj.GetSiteConfig(SiteId);
                if (mySite != null)
                {
                    mySite.SiteUrl = cleanArg(parameters[2]);
                }
                else
                    OutputMethod("[" + SiteId + "]Edit-site : unknown siteId " + SiteId, Output.ERROR);
            }

            else
                OutputMethod("Edit-site : parameters missing", Output.ERROR);
        }

        public void VisitSerializeallMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (SiteObj.Sites != null)
            {
                foreach (SypSite mySite in SiteObj.Sites)
                {
                    SiteObj.SerializeToXml(mySite);
                }
            }
        }

        public void VisitSupprallMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (SiteObj.Sites != null)
            {
                foreach (SypSite mySite in SiteObj.Sites)
                {
                    int SiteId = mySite.SiteId;
                    /*SiteObj.AddAction(SiteId, SypGarbage.TMP_FOLDER + SiteId, SyncAction.SUPPR_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(SiteId, SypGarbage.SITES_CONF + SiteId + SypGarbage.XML_EXTENSION, SyncAction.SUPPR_CONF, SyncMode.LOCAL);

                    SiteObj.AddAction(SiteId, SypGarbage.THUMBNAILS_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.PAGE_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.PICTURES_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.IMAGES_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.STYLESHEET_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.JAVASCRIPT_FOLDER, SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypGarbage.DEFAULT_PAGE, SyncAction.SUPPR_FILE, SyncMode.ONLINE);*/

                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.SITE_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.SITE_CONF, null, SiteId), SyncAction.SUPPR_CONF, SyncMode.LOCAL);

                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.THUMBNAIL_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.CATEGORIES_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.PICTURE_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.IMAGE_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.STYLESHEET_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.JAVASCRIPT_FOLDER, null), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.BO_PAGE, null), SyncAction.SUPPR_FILE, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.INDEX_PAGE, null), SyncAction.SUPPR_FILE, SyncMode.ONLINE);

                    OutputMethod("Suppr-site [" + SiteId + "] site deleted successfully", Output.OUT);
                }
                SiteObj.Sites.Clear();
            }
        }

        public override void VisitSupprMethod(SypSiteHandler SiteObj,  string[] parameters)
        {
            
            if (parameters.Length > 1)
            {
                int SiteId = -1;
                try
                {
                    SiteId = int.Parse(cleanArg(parameters[1]));
                }
                catch (Exception)
                {
                    OutputMethod("Suppr-site : parameter is not a number", Output.ERROR);
                    return;
                }
                SypSite mySite = SiteObj.GetSiteConfig(SiteId);
                if (mySite != null)
                {
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.SITE_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.LOCAL);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.SITE_CONF, null, SiteId), SyncAction.SUPPR_CONF, SyncMode.LOCAL);

                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.THUMBNAIL_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.CATEGORIES_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.PICTURE_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.IMAGE_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.STYLESHEET_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.JAVASCRIPT_FOLDER, null, SiteId), SyncAction.SUPPR_FOLDER, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.BO_PAGE, null, SiteId), SyncAction.SUPPR_FILE, SyncMode.ONLINE);
                    SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE, SypPathRef.INDEX_PAGE, null, SiteId), SyncAction.SUPPR_FILE, SyncMode.ONLINE);

                    SiteObj.Sites.Remove(mySite);
                    //SiteObj.AutoSyncList.Remove(mySite.SiteId);
                    //SiteObj.SiteSyncList.Remove(mySite.SiteId);
                    OutputMethod("Suppr-site [" + mySite.SiteId + "] site deleted successfully", Output.OUT);
                }
                else
                    OutputMethod("["+SiteId+"]Suppr-site : unknown siteId "+SiteId, Output.ERROR);
            }
            else
                OutputMethod("Suppr-site : parameter missing", Output.ERROR);
        }

        /*
        public void VisitZipallMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            if (SiteObj.SiteSyncList != null)
            {
                try
                {
                    if (SiteObj.SiteSyncList.Keys != null)
                    {
                        int cpt = 0;
                        foreach (int key in SiteObj.SiteSyncList.Keys)
                        {
                            OutputMethod(cpt.ToString() + SypGarbage.COMMAND_SEPARATOR + SiteObj.SiteSyncList.Count, Output.PROGRESS_POS);
                            VisitZipMethod(SiteObj, new string[] { "", key.ToString() });
                            cpt++;
                        }
                        OutputMethod(null, Output.PROGRESS_RESET_POS);
                    }
                }
                catch (Exception e)
                {
                    OutputMethod("Zipall-synchronise : error catched, " + e.ToString(), Output.ERROR);
                }

            }
        }
        
        public void VisitZipMethod(SypSiteHandler SiteObj, string[] parameters)
        {
            OutputMethod(null, Output.LOCK);
            bool UpdateSiteConf = false;
            if (parameters.Length > 1)
            {
                int SiteId = -1;
                try
                {
                    SiteId = int.Parse(cleanArg(parameters[1]));
                }
                catch (Exception)
                {
                    OutputMethod("Zip-album : one or more parameters are not a number", Output.ERROR);
                    return;
                }
                SypSite mySite = SiteObj.GetSiteConfig(SiteId);

                if (mySite != null && mySite.CategorysList != null)
                {
                    if (mySite.ZipMode)
                    {
                        int cpt = 1;
                        OutputMethod(GetRessources("ProgressZipping") + " " + mySite.SiteTitle, Output.PROGRESS_STATUS);
                        foreach (Category alb in mySite.CategorysList)
                        {
                            if (alb.AlbumList != null)
                            {
                                foreach (Album sect in alb.AlbumList)
                                {
                                    if (mySite.AlbumToZip != null && mySite.AlbumToZip.Contains(sect.id))
                                    {
                                        if (sect.PicturesList != null)
                                        {
                                            //string myAlbumZipFile = SypGarbage.TMP_FOLDER + SiteId + "/" + SypGarbage.LOCAL_FOLDER + SypGarbage.ZIP_FOLDER + sect.id + SypGarbage.ZIP_EXTENSION;
                                            string myAlbumZipFile = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.ZIP_FILE, null, mySite.SiteId, sect.id);
                                            FileStream zipFile = null;
                                            if (File.Exists(myAlbumZipFile))
                                            {
                                                //File.Delete(myAlbumZipFile);
                                                zipFile = File.OpenWrite(myAlbumZipFile);
                                            }
                                            else
                                            {
                                                zipFile = File.Create(myAlbumZipFile);
                                            }
                                            using (ZipOutputStream s = new ZipOutputStream(zipFile))
                                            {
                                                s.SetLevel(1);
                                                byte[] buffer = new byte[4096];
                                                foreach (Picture pict in sect.PicturesList)
                                                {
                                                    FileInfo myPictFile = new FileInfo(SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.PICTURE_FILE, null, mySite.SiteId, sect.id, pict.Id));
                                                    ZipEntry entry = new ZipEntry(myPictFile.Name);
                                                    entry.DateTime = DateTime.Now;
                                                    s.PutNextEntry(entry);

                                                    //string file = SypGarbage.TMP_FOLDER + SiteId + "/" + SypGarbage.LOCAL_FOLDER + SypGarbage.PICTURES_FOLDER + SypGarbage.PICTURE_PREF + pict.Id + SypGarbage.PICTURE_EXTENSION;
                                                    string file = SypPathHandler.GetPath(SypPathMode.LOCAL, SypPathRef.PICTURE_FILE, null, mySite.SiteId, -1, pict.Id);
                                                    using (FileStream fs = File.OpenRead(file))
                                                    {
                                                        int sourceBytes;

                                                        do
                                                        {
                                                            sourceBytes = fs.Read(buffer, 0, buffer.Length);
                                                            s.Write(buffer, 0, sourceBytes);
                                                        } while (sourceBytes > 0);
                                                    }
                                                }
                                                s.Finish();
                                                s.Close();
                                            }
                                            //SiteObj.AddAction(SiteId, SypGarbage.ZIP_FOLDER + sect.id + SypGarbage.ZIP_EXTENSION, SyncAction.ADD_ZIP, SyncMode.ONLINE);
                                            SiteObj.AddAction(SiteId, SypPathHandler.GetPath(SypPathMode.ONLINE,SypPathRef.ZIP_FILE, null, mySite.SiteId, sect.id), SyncAction.ADD_ZIP, SyncMode.ONLINE);
                                            UpdateSiteConf = true;
                                        }
                                        mySite.AlbumToZip.Remove(sect.id);
                                    }
                                }
                            }
                            OutputMethod(cpt.ToString() + SypGarbage.COMMAND_SEPARATOR + mySite.CategorysList.Count, Output.ZIP_STEP);
                            cpt++;
                        }

                        if (UpdateSiteConf)
                            SiteObj.SerializeToXml(mySite);
                    }
                    else
                        OutputMethod(mySite.CategorysList.Count.ToString() + SypGarbage.COMMAND_SEPARATOR + mySite.CategorysList.Count, Output.ZIP_STEP);

                }

            }
            OutputMethod(null, Output.UNLOCK);
        }
        */


        #endregion
    }
}
